package comp.style.state
{
	import comp.UIComponent;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	
	public class Skin implements Istate
	{
		public function Skin(skin:Class=null,defaultSkin:Class=null)
		{
			super();
			_skin=skin;
			_defaultSkin=defaultSkin
		}
		
		//****************** 接口 *****************
		/**
		 * 创建皮肤
		 */
		public function create():void
		{
			if(_skin)
			{
				_realSkin=new _skin();
				this.state=1;
			}else if(_defaultSkin)
			{
				_realSkin=new _defaultSkin();
				this.state=1;
			}
		}
		
		public function doState(ui:*):*
		{
			if(_realSkin)
			{
				if(ui is UIComponent)
				{
					var s:String=ui.getStyle("backgroundSize")
					if(s && s.toLocaleLowerCase()!="auto")
					{
						_realSkin.scaleX=Number(s);
						_realSkin.scaleY=Number(s);
						
					}else
					{
						_realSkin.width=ui.width;
						_realSkin.height=ui.height;	
					}
				}else
				{
					_realSkin.width=ui.width;
					_realSkin.height=ui.height;	
				}
				ui.addChildAt(_realSkin,0);
			}
		}
		
		public function canelState(ui:*):*
		{
			if(_realSkin && _realSkin.parent)
				_realSkin.parent.removeChild(_realSkin);	
		}

		public function get state():int
		{
			return _state;
		}

		public function set state(value:int):void
		{
			_state = value;
		}

		public function get stateName():String
		{
			return _stateName;
		}

		public function set stateName(value:String):void
		{
			_stateName = value;
		}
		
		protected var _stateName:String;
		
		protected var _state:int=0;//
		
		protected var _skin:Class;
		protected var _defaultSkin:Class;
		
		protected var _realSkin:DisplayObject;
		
	}
}